package com.haiyi.software.app;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class ActivityModifyUsername extends Activity {

	private Button btn_saveback;

	private EditText Editx_username;

	private String username;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_modify_username);
		getParameters();
		initComp();
	}

	private void getParameters() {

		this.username = this.getIntent().getStringExtra("username");
	}

	private void initComp() {

		this.btn_saveback = (Button) this.findViewById(R.id.btn_saveback);
		this.Editx_username = (EditText) this.findViewById(R.id.Editx_username);
		this.btn_saveback.setOnClickListener(saveClick);
		this.Editx_username.setText(this.username);
	}

	private OnClickListener saveClick = new OnClickListener() {

		@Override
		public void onClick(View v) {

			if (ckData()) {

				Intent intent = new Intent();

				intent.putExtra("username", Editx_username.getText().toString()
						.trim());

				setResult(ActivityModifyInformation.SHOW_SUB_ACTIVITY_USERNAME,
						intent);

				ActivityModifyUsername.this.finish();
			}
		}
	};

	private Boolean ckData() {

		Boolean bmin = Editx_username.getText().toString().trim().length() > 0;
		Boolean bmax = Editx_username.getText().toString().trim().length() <= 12;

		if (!bmin) {

			Toast.makeText(this, "请输入昵称", Toast.LENGTH_LONG).show();
		}

		if (!bmax) {

			Toast.makeText(this, "昵称应在12个字符以内", Toast.LENGTH_LONG).show();
		}
		return bmin && bmax;
	}
}
